<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
        <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!-- HTML5文档头 -->
<!DOCTYPE html>
<!-- lang="zh-cn"，此网页基本是中文内容 -->
<html lang="zh-cn">

	<head>
		<meta charset="utf-8" />
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		<!-- 使用最新的IE兼容模式渲染此网页 -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<!-- 在双核浏览器下，默认使用webkit内核，由360浏览器提出 -->
		<meta name="renderer" content="webkit">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--<link rel="shortcut icon" href=""/>-->
		<!-- 强大的CSS Reset库 -->
		<link href="http://cdn.bootcss.com/normalize/5.0.0/normalize.min.css" rel="stylesheet">
		<script src="<%=request.getContextPath() %>/statics/common/vendor/jquery.min.js"></script>
		<!--<link href="vendor/bootstrap.css" rel="stylesheet">-->
		<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
		<link rel="stylesheet" href="<%=request.getContextPath() %>/statics/common/styles/index.css" />
		<script src="<%=request.getContextPath() %>/statics/common/vendor/bootstrap.min.js"></script>
		<!-- 让IE9以下的浏览器支持HTML5标签 -->
		<!--[if lt IE 9]>
        	<script src="http://cdn.bootcss.com/html5shiv/r29/html5.js"></script>
        	<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
	</head>

	<body>
	<nav class="navbar navbar-default" role="navigation">
			<div class="container-fluid">
				<!-- Brand and toggle get grouped for better mobile display -->
				<div class="navbar-header">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-9" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
					<a class="navbar-brand" href="<%=request.getContextPath() %>/index.jsp">嗒嗒嗒博客</a>
					</div>
				<div class="navbar-collapse collapse" id="bs-example-navbar-collapse-9" aria-expanded="false" style="height: 1px;">
					<ul class="nav navbar-nav navbar-right">
					<c:if test="${empty user}">
						<li><a href="#" data-toggle="modal" data-target="#myModal" id="loginBtn">登录</a></li>
						<li><a href="#" data-toggle="modal" data-target="#myModal1">注册</a></li>
					</c:if>
					<c:if test="${!empty user}">
						<li><a href="#">${user.name}</a></li>
						<li><a href="<%=request.getContextPath() %>/views/blog/blog-list.jsp">管理主页</a></li>
						<li><a href="<%=request.getContextPath() %>/user/logout">注销</a></li>
					</c:if>
					</ul>
				</div>
			</div>
		</nav>
		<!--登录-->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content loginbox">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<h4 class="modal-title">登录</h4>
					</div>
					<form class="form-signin" role="form" id="loginForm" method="post">
						<input type="text" name="code" class="form-control" placeholder="请输入用户名" required autofocus>
						<input type="password" name="password" class="form-control" placeholder="请输入密码" required>
						<div class="checkbox">
							<label><input type="checkbox" value="remember-me"> 记住我？</label>
						</div>
						<button class="btn btn-lg btn-primary btn-block" onclick="login()">登录</button>
					</form>
				</div>
			</div>
		</div>
		<!--注册-->
		<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content loginbox">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<h4 class="modal-title">注册</h4>
					</div>
					<form class="form-signin" role="form" action="<%=request.getContextPath()%>/user/register" method="post">
						<input type="text" name="code" class="form-control" placeholder="请输入用户名" required autofocus>
						<input type="password" name="password" class="form-control" placeholder="请输入密码" required>
						<input type="text" name="name" class="form-control" placeholder="请输入姓名" required>
						
						<button class="btn btn-lg btn-primary btn-block" type="submit">注册</button>
					</form>
				</div>
			</div>
		</div>
		<div class="banner" style="background-image: url('<%=request.getContextPath() %>/${article.bgImage }');"> 
			<h1 class="blogname">${article.blogName }</h1>
			<p>${article.description }</p>
		</div>
		<section class=" container content">
			<div class="col-md-8 col-sm-12 col-xs-12">
				<ul class="clearfix">
					<li class="list clearfix">
						<div class="list-tit ">
							<h2>${article.title}</h2>
							<p class="item1">
								<span class="glyphicon glyphicon-th-large"></span><span class="classify">${article.categoryName }</span>
								<span class="glyphicon glyphicon-time"></span><span class="introduce-time">发布时间：${article.createTime }</span>
								<span class="glyphicon glyphicon-eye-open"></span><span class="read"><span class="read-more">${article.readTimes }</span></span>
							</p>
							<p>${article.content}</p>
						</div>
					</li>
				</ul>
				<div class="row">
					<ul class="list-group" id="discussUl">
						<li class="list-group-item active">评论列表</li>
						<c:forEach items="${discussList }" var="discuss">
							<li class="list-group-item">
								<div class="media">
									<a class="pull-left" href="#">
										<img class="media-object" src="<%=request.getContextPath() %>/${discuss.photo }">
									</a>
									<div class="media-body">
										<h4 class="media-heading">${discuss.userName }</h4>
										<p>${discuss.content}</p>
										<p class="item">
											<span class="introduce-time">${discuss.createTime}</span>
											<span class="reply"><a href="#">回复(0)</a></span>
									</div>
								</div>
							</li>
						</c:forEach>
					</ul>
					<form method="post" id="discussForm">
						<div class="form-group">
							<input type="hidden" name="articleId" value="${article.id }">
							<input type="text" name="content" id="discussContent" class="form-control comment" placeholder="请发表评论">
						</div>
						<button type="button" onclick="discuss.answer(${user.id})" class="btn btn-primary btn-block">发表</button>
					</form>
				</div>
			</div>
			<div class="col-md-4 col-sm-12 col-xs-12 r-con">
				<ul class="list-group" id="authorRank">
					<li class="list-group-item active">阅读排行</li>
				</ul>
				<ul class="list-group" id="categoryInfo">
					<li class="list-group-item active">文章分类</li>
					
				</ul>
			</div>

		</section>
		<c:set var="ctx" value="<%=request.getContextPath()%>"></c:set>
		<script>
			var authorId = '${article.userId}';
			window.ctx = '${ctx}';
			var discuss = {
					answer:function(userId){
						if(userId==null){
							$('#loginBtn').click();
						}else{
							$.post('<%=request.getContextPath()%>/sys/addDiscuss',$('#discussForm').serialize(),
									function(data){
								if(data){
									var html = [];
									html.push('<li class="list-group-item">');
									html.push('	<div class="media">');
									html.push('			<a class="pull-left" href="'+ window.ctx +'/sys/authorBlog?userId='+ data.userId +'&pageNo=1">');
									html.push('				<img class="media-object" src="'+ window.ctx +'/'+ data.photo +'">');
									html.push('			</a>');
									html.push('		<div class="media-body">');
									html.push('			<h4 class="media-heading">'+ data.userName +'</h4>');
									html.push('			<p>'+ data.content +'</p>');
									html.push('			<p class="item">');
									html.push('<span class="introduce-time">'+ data.createTime +'</span>');
									html.push('			<span class="reply"><a href="#">回复(0)</a></span>');
									html.push('		</div>');
									html.push(' </div>');
									html.push('</li>');
									$('#discussUl').append(html.join(''));
									$('#discussContent').val('');
								}
							});
						}
						
					}
			}
		</script>
		<script src="${ctx}/statics/sys/scripts/rank.js"></script>
		<script src="<%=request.getContextPath() %>/statics/common/scripts/login.js"/></script>
	</body>

</html>